/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SpringTAI.web;

/**
 *
 * @author Łukasz Kolasa, Krzysztof Nyznar
 */
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;
import java.util.Map;
import java.util.HashMap;

import java.util.Date;

import SpringTAI.service.PersonManager;

/**
 *
 * @author Krzysztof Nyznar
 */
public class ContactController implements Controller {

    protected final Log logger = LogFactory.getLog(getClass());
    
    private PersonManager personManager;
       
    @Override
    public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
         
        String now = (new Date()).toString();
        logger.info("Returning test view with now: " + now );
        
        Map<String, Object> myModel = new HashMap<String, Object>();
        //myModel.put("now", now);
        myModel.put("persons", this.personManager.getPersons());
        
        return new ModelAndView("contact", "model", myModel);
    }
    
    
    
    public void setPersonManager(PersonManager personManager) {
        this.personManager = personManager;
    }
    
}